<?php
/**
 * Name: SmsLogController.class.php
 * Description:
 * User: DIY
 * Date: 2016/9/24
 * Time: 18:12
 */

namespace Admin\Controller;


use Admin\Library\BootstrapPage;
use Common\Logic\SmsLogic;
use Common\Model\SmsLogModel;
use Common\Model\SmsTemplateModel;

class SmsLogController extends BaseController{

    /*
     * 短信记录
     * */
    public function index(){

        $SmsLogModel = new SmsLogModel();
        $data = I('get.');
        //取得模版列表
        $type_list = S('sms_type_list');
        if(empty($type_list)){
            $SmsTemplateModel = new SmsTemplateModel();
            $type_list = $SmsTemplateModel->field('title,type')->select();
            S('sms_type_list',$type_list);
        }
        $count = $SmsLogModel->getSmsLogCount($data);
        $Page = new BootstrapPage($count,20);
        $limit = $Page->firstRow.','.$Page->listRows;
        $list['page'] = $Page->show();
        $list['list'] = $SmsLogModel->getSmsLogList($data,$limit);
        $this->assign('type_list',$type_list);
        $this->assign('list',$list);
        $this->display();
    }

    public function show($id){

        $SmsLogModel = new SmsLogModel();
        $sms_log = $SmsLogModel->getSmsLogByID($id);
        $this->assign('sms_log',$sms_log);
        $this->display();
    }

    /*
     * 重新发送短信
     * */
    public function send($id){
        $SmsLogic = new SmsLogic();
        //$SmsLogic->sendSms('13076007520','test','XF'.time(),array());
        $send =$SmsLogic->reSendSms($id);
        if($send['result']=='success'){
            $this->success('发送成功',U('Admin/SmsLog/index'));
        }
        else{
            $this->error('发送失败!原因:'.$send['msg']);
        }
    }
}